import {
  GetNotifyListQueryType,
  PublishNotifyType,
  AddMessageType,
  ProcessMessageType,
} from "../service/systemNotify";

const mockNotifyList: PublishNotifyType[] = [
  {
    id: "1",
    type: "设备告警",
    content: "实验室A区离心机运行异常，请及时检查维修",
    createTime: new Date(Date.now() - 5 * 60 * 1000).toISOString(), // 5分钟前
    status: "unread",
  },
  {
    id: "2",
    type: "设备告警",
    content: "PCR扩增仪温度传感器故障，已自动停机",
    createTime: new Date(Date.now() - 15 * 60 * 1000).toISOString(), // 15分钟前
    status: "unread",
  },
  {
    id: "3",
    type: "系统通知",
    content: "系统将于今晚23:00-次日1:00进行维护升级",
    createTime: new Date(Date.now() - 2 * 60 * 60 * 1000).toISOString(), // 2小时前
    status: "read",
  },
  {
    id: "4",
    type: "设备告警",
    content: "显微镜光源亮度不足，建议更换灯泡",
    createTime: new Date(Date.now() - 4 * 60 * 60 * 1000).toISOString(), // 4小时前
    status: "unread",
  },
  {
    id: "5",
    type: "系统通知",
    content: "新用户张三的设备预约申请待审批",
    createTime: new Date(Date.now() - 6 * 60 * 60 * 1000).toISOString(), // 6小时前
    status: "read",
  },
];

// 生成唯一ID
const generateId = (): string => {
  return Date.now().toString() + Math.random().toString(36).substr(2, 9);
};

// 模拟延迟
const delay = (ms = 300): Promise<void> => {
  return new Promise((resolve) => setTimeout(resolve, ms));
};

// 消息列表
export const mockGetNotifyList = async (
  params: GetNotifyListQueryType
): Promise<{
  status: number;
  data: PublishNotifyType[] | null;
  message: string;
}> => {
  await delay();

  return {
    status: 0,
    data: mockNotifyList,
    message: "获取消息列表成功",
  };
};

// 发布消息的mock
export const mockPublishNotify = async (
  params: PublishNotifyType
): Promise<{
  status: number;
  data: PublishNotifyType | null;
  message: string;
}> => {
  await delay();
  return {
    status: 0,
    data: params,
    message: "发布消息成功",
  };
};

// 添加系统消息
export const mockAddMessage = async (
  params: AddMessageType
): Promise<{
  status: number;
  data: AddMessageType | null;
  message: string;
}> => {
  await delay();
  return {
    status: 0,
    data: params,
    message: "添加消息成功",
  };
};

// 处理系统消息
export const mockProcessMessage = async (
  params: ProcessMessageType
): Promise<{
  status: number;
  data: ProcessMessageType | null;
  message: string;
}> => {
  await delay();
  return {
    status: 0,
    data: params,
    message: "处理消息成功",
  };
};
